home *** CD-ROM | disk | FTP | other *** search
- <%
- '+-------------------------------------------------------------------------
- '
- ' Microsoft Windows Media
- ' Copyright (C) Microsoft Corporation. All rights reserved.
- '
- ' File: wmsServerHash.inc
- '
- ' Contents: Ops to hash and unhash the server name passed in the query string
- '
- ' Comments: Included by wmsconnect.inc
- '
- '--------------------------------------------------------------------------
-
- %><script language="JScript" RUNAT=Server>
- ////////////////////////////////////////////////////////////////////
- function GetTimestamp()
- {
- var d;
- var szRetVal;
-
- d = new Date();
-
- szRetVal = new String( d.getSeconds() );
- szRetVal += d.getMilliseconds();
- return( szRetVal );
- }
- </script><%
-
- on error resume next
- Dim g_objDictionary
- g_objDictionary = empty
-
- '//////////////////////////////////////////////////////////////////////////
- private Function CreateHashKey()
- Dim strVal
- Dim strGuid
- Dim objGuidGen
- Set objGuidGen = Server.CreateObject( "Scriptlet.TypeLib" )
- strGuid = objGuidGen.Guid
- strGuid = Replace( strGuid, "{", "X" )
- strGuid = Replace( strGuid, "}", "Y" )
- strGuid = Replace( strGuid, "-", "Z" )
-
- strVal = Mid( strGuid, 2, 8 ) & GetTimestamp()
- ' strVal = strGuid
- CreateHashKey = strVal
- End Function
-
- '//////////////////////////////////////////////////////////////////////////
- '//
- '// Wrapper for ReverseHashServerName
- '//
- public Function ServerNameToHashKey( strServerName, bAddIfNonexistent )
- Dim strKey
- strKey = ""
-
- if( 0 >= Len( strServerName ) ) then
- ServerNameToHashKey = ""
- Exit Function
- end if
-
- if( 0 = StrComp( "localhost", strServerName, vbTextCompare ) ) then
- strServerName = s_WMSAdmin.GetCanonicalComputerName( "localhost", WMS_ComputerNameNetBIOS )
- end if
-
- strServerName = LCase( strServerName )
- strKey = ReverseHashServerName( strServerName )
- if( bAddIfNonexistent and ( 0 = Len( strKey ) ) ) then
- strKey = CreateHashKey
- ' strKey = "hk" & Left( Request.ServerVariables( "INSTANCE_ID" ), 4 ) & GetTimestamp()
- if( IsEmpty( g_objDictionary ) ) then
- Set g_objDictionary = Session( "SvrDictionary" )
- end if
- Do While( g_objDictionary.Exists( strKey ) )
- strKey = "hk" & GetTimestamp()
- Loop
- g_objDictionary.Add CStr( strKey ), CStr( strServerName )
- end if
-
- ServerNameToHashKey = strKey
- End Function
-
-
- '//////////////////////////////////////////////////////////////////////////
- public Sub RemoveServerFromHash( szHashKey )
- if( 0 < Len( szHashKey ) ) then
- if( IsEmpty( g_objDictionary ) ) then
- Set g_objDictionary = Session( "SvrDictionary" )
- end if
- if( g_objDictionary.Exists( CStr( szHashKey ) ) ) then
- g_objDictionary.Remove( CStr( szHashKey ) )
- end if
- end if
- End Sub
-
-
- '//////////////////////////////////////////////////////////////////////////
- '
- ' Resolve a hash key to the original servername
- '
- public Function ServerHashKeyToName( strServerHashKey )
- on error resume next
- if( IsEmpty( g_objDictionary ) ) then
- Set g_objDictionary = Session( "SvrDictionary" )
- end if
- if( g_objDictionary.Exists( SafeUnescape( strServerHashKey ) ) ) then
- ServerHashKeyToName = CStr( g_objDictionary.Item( SafeUnescape( strServerHashKey ) ) )
- else
- ServerHashKeyToName = ""
- end if
- End Function
-
-
- '//////////////////////////////////////////////////////////////////////////
- ' Used for debugging only
- public Sub DumpServerHash()
- exit sub ' remove this line if you wish to make use of this subroutine
- Dim serverDictionary
- Dim lenDict
- Dim rgKeys
- Dim rgItems
-
- if( IsEmpty( g_objDictionary ) ) then
- Set g_objDictionary = Session( "SvrDictionary" )
- end if
- if( IsEmpty( g_objDictionary ) ) then
- Exit Sub
- end if
-
- lenDict = g_objDictionary.Count
- rgKeys = g_objDictionary.Keys
- rgItems = g_objDictionary.Items
-
- Response.Write( "Debug info: <br><br><table cellspacing=1 cellpadding=4 border=1 cols=3><th colspan=3>Servers (" & lenDict & ") in hash table</th><tbody>" )
- i = 0
- For i = 0 to lenDict - 1
- Response.Write( "<tr><td>" & i & ") " & "</td><td>" & Server.HTMLEncode( rgKeys( i ) ) & "</td><td>" & Server.HTMLEncode( rgItems( i ) ) & "</td></tr>" )
- Next
- Response.Write( "</tbody></table>" )
- serverDictionary = ""
- End Sub
-
-
- '//////////////////////////////////////////////////////////////////////////
- '// Private methods
- '//////////////////////////////////////////////////////////////////////////
-
-
- '//////////////////////////////////////////////////////////////////////////
- private Function ReverseHashServerName( strServerName )
- Dim rgKeys
- Dim rgItems
- Dim strEachServerName
- Dim i
-
- on error resume next
- dbgNumItemsVisited = 0
-
- if( IsEmpty( g_objDictionary ) ) then
- Set g_objDictionary = Session( "SvrDictionary" )
- end if
- if( IsEmpty( g_objDictionary ) ) then
- ReverseHashServerName = ""
- Exit Function
- end if
- rgKeys = g_objDictionary.Keys
- rgItems = g_objDictionary.Items
-
- For i = 0 to g_objDictionary.Count - 1
- dbgNumItemsVisited = dbgNumItemsVisited + 1
- strEachServerName = CStr( rgItems( i ) )
- if( ( 0 < Len( strEachServerName ) ) and ( 0 = StrComp( strServerName, strEachServerName, vbTextCompare ) ) ) then
- ReverseHashServerName = rgKeys( i )
- Exit Function
- end if
- Next
-
- ' Session( "dbg" ) = "ReverseHashServerName failed to find " & strServerName & "<br>"
- ReverseHashServerName = ""
- End Function
-
- '////////////////////////////////////////////////////////////////
- '
- ' Free the various globals we created by server-side-including this file
- '
- Sub WMSServerHashASPCleanup
- on error resume next
- g_objDictionary = nothing
- End Sub
- %>